<?php
	require('config.php');
	$user_id=$_REQUEST['user_id'];
	$orderId=$_REQUEST['orderId'];
	$sever=$_REQUEST['sever'];
	$diver=$_REQUEST['diver'];
	$ni=$_REQUEST['ni'];
	$shopContent=$_REQUEST['shopContent'];
	$json=$_REQUEST['json'];
	$json=json_decode($json,true);
	$time=date('Y-m-d H:i:s');
	if($ni==0 || $ni=='0') $ni=1;
	else $ni=0;
	$sql="SELECT * FROM ".$oto."_goods_appraises where orderId='{$orderId}'";
	$result=$db->query($sql);
	while($row=$result->fetch_assoc()){
		$pingjia[]=$row;//将取得的所有数据赋值给person_info数组
	}
	$sql="SELECT * FROM ".$oto."_orders where orderId='{$orderId}'";
	$result=$db->query($sql);
	while($row=$result->fetch_assoc()){
		$orders[]=$row;//将取得的所有数据赋值给person_info数组
	}
	$shopId=$orders[0]['shopId'];
	if(isset($pingjia))
	{
		$data[0]['pan']='-1';
		$data[0]['msg']='已经评价过了';
	}
	else
	{
		$sql="INSERT INTO ".$oto."_goods_appraises (`shopId`,`orderId`,`goodsId`,`userId`,`serviceScore`,`timeScore`,`content`,`createTime`,`anonymity`) VALUES ('$shopId','$orderId','0','$user_id','$sever','$diver','$shopContent','$time','$ni')";
	    $result=$db->query($sql);
	    for($i=0;$i<count($json);$i++)
	    {
	    	$goodsId=$json[$i]['id'];
	    	$xing=$json[$i]['xing'];
	    	$content=$json[$i]['content'];
	    	$sql="INSERT INTO ".$oto."_goods_appraises (`shopId`,`orderId`,`goodsId`,`userId`,`goodsScore`,`content`,`createTime`,`anonymity`) VALUES ('$shopId','$orderId','$goodsId','$user_id','$xing','$content','$time','$ni')";
	   		$result=$db->query($sql);
	    }
	    $data[0]['pan']='1';
	    $data[0]['msg']="评价成功";
	}
	echo json_encode($data);
?>